<template>
    <div class="question-card-container">
        <el-badge v-for="(question, index) in questions" :key="question.id" class="question-badge"
            :value="question.status === 'done' ? '✔' : null" :hidden="question.status !== 'done'"
            :class="getStatusClass(question)" @click="handleClick(question)">
            <div class="question-box">
                {{ question.number?.toString().padStart(2, '0') || '--' }}
            </div>
        </el-badge>
    </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
    questions: {
        type: Array,
        required: true,
        // 每个对象格式：
        // { id: 1, number: 1, status: 'done' | 'error' | 'notDone' | 'selected' }
    },
    modelValue: Number // 当前选中的题号
})

const emit = defineEmits(['clickItem'])

function handleClick(question) {
    emit('clickItem', question)
}

function getStatusClass(question) {
    //如果被点击了
    if (question.isClicked) {
        // 选中样式
        return 'selected'
    } else
    //没有被点击的
    {
        switch (question.status) {
            // 做过样式
            case 'done':
                return 'done'
            // 做错样式
            case 'error':
                return 'error'
            // 未做样式
            default:
                return 'notDone'
        }
    }

}
</script>

<style scoped lang="scss">
.question-card-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 10px;
    overflow-y: auto;
    width: max-content;
}

.question-badge {
    width: 24px;
    height: 24px;
    text-align: center;
    cursor: pointer;
}

.question-box {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}


/* 状态样式 */
.done {
    border: 1px solid #409EFF;
    border-radius: 6px;
    color: #409EFF;
}

.selected {
    background-color: #409EFF;
    color: white;
    border-radius: 6px;
}

.active-done {
    background-color: #409EFF;
    color: white;
    border-radius: 6px;
    position: relative;
}

.error {
    border: 1px solid #ff0000;
    border-radius: 6px;
    color: #ff0000;
}

.notDone {
    border: 1px solid #ccc;
    border-radius: 6px;
    color: #999;
}

//使得角标badge变成圆形边框的
:deep(.el-badge__content) {
    font-size: 10px;
    padding: 0;
    width: 10px;
    height: 10px;
    line-height: 10px;
    text-align: center;
    border-radius: 50%;
    background-color: #fff;
    border: 1px solid #0099ff;
    color: #0099ff;
}
</style>
